package com.guigu.www.luolujin.Service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.guigu.www.luolujin.Service.LljTemplateWholesomeService;
import com.guigu.www.mapper.TemplateWholesomeDetailsMapper;
import com.guigu.www.mapper.TemplateWholesomeMapper;
import com.guigu.www.mapper.WholesomeInnerMapper;
import com.guigu.www.pojo.*;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * 作者 罗露金
 */
@Service
public class LljTemplateWholesomeServiceImpl implements LljTemplateWholesomeService {
    @Autowired
    TemplateWholesomeMapper mapper;
    @Autowired
    WholesomeInnerMapper innerMapper;
    @Autowired
    TemplateWholesomeDetailsMapper detailsMapper;
    @Override
    public PageVo<TemplateWholesome> pageTemplateWholesome(Integer pageNum, Integer pageSize, String tempWhoTitle) {
        QueryWrapper<TemplateWholesome> wrapper = new QueryWrapper<>();
        wrapper.like("temp_who_title",tempWhoTitle);
        Page page = new Page(pageNum, pageSize);
        IPage iPage = mapper.selectPage(page, wrapper);
        PageVo<TemplateWholesome> PageVo = new PageVo<>();
        PageVo.setRows(iPage.getRecords());
        PageVo.setTotal(iPage.getTotal());
        return PageVo;
    }

    @Override
    public void updateTemplateWholesome(Integer tempWhoId, Integer tempWhoState) {
        TemplateWholesome templateWholesome = new TemplateWholesome();
        templateWholesome.setTempWhoId(tempWhoId);
        templateWholesome.setTempWhoState(tempWhoState);
        mapper.updateById(templateWholesome);
    }

    @Override
    public void insertTemplateWholesome(TemplateWholesome TemplateWholesome, Integer[] tempWhoDeId) {
        mapper.insert(TemplateWholesome);
        for(Integer id:tempWhoDeId){
            WholesomeInner wholesomeInner = new WholesomeInner(null,TemplateWholesome.getTempWhoId(),id);
            innerMapper.insert(wholesomeInner);
        }
    }

    @Override
    public List<TemplateWholesomeDetails> queryById(int tempWhoId) {
        return detailsMapper.queryById(tempWhoId);
    }
}
